package com.woniu.cloud.storeassembly.apiimpl;

import com.woniu.cloud.api.StoreRevenueApi;
import com.woniu.cloud.common.dto.Result;
import com.woniu.cloud.entity.TStoreRevenue;
import com.woniu.cloud.form.StoreRevenueInsertForm;
import com.woniu.cloud.form.StoreRevenueSelectForm;
import com.woniu.cloud.storeassembly.service.ITStoreRevenueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 流水表 前端控制器
 * </p>
 *
 * @author hyy
 * @since 2021-09-22
 */
@RestController
@Slf4j
public class StoreRevenueApiImpl implements StoreRevenueApi {

    @Resource
    private ITStoreRevenueService storeRevenueService;


    @Override
    @PostMapping("insertStoreRevenue")
    public  Result insertStoreRevenue(@RequestBody StoreRevenueInsertForm storeRevenueInsertForm) {
        log.info("添加流水->storeRevenueForm:{}",storeRevenueInsertForm);
        if (null==storeRevenueInsertForm) {
            return Result.fail("参数异常",null);
        }
        try {
            TStoreRevenue storeRevenue = new TStoreRevenue();
            BeanUtils.copyProperties(storeRevenueInsertForm,storeRevenue);
            log.info("开始添加->store:{}",storeRevenue);
            return storeRevenueService.insertStoreRevenue(storeRevenue);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("服务异常",null);
        }
    }

    @Override
    @PostMapping("getStoreRevenue")
    public Result getStoreRevenue(@RequestBody  StoreRevenueSelectForm storeRevenueForm) {
        log.info("获取流水->storeRevenueForm:{}",storeRevenueForm);
        if (null==storeRevenueForm) {
            return Result.fail("参数异常",null);
        }
        try {
            log.info("开始查找->store:{}",storeRevenueForm);
            return storeRevenueService.getStoreRevenue(storeRevenueForm);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("服务异常",null);
        }
    }
}
